// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
//import Vue from 'vue'
//import App from './App'
//import router from './router'
//
//Vue.config.productionTip = false
//
///* eslint-disable no-new */
//new Vue({
//el: '#app',
//router,
//template: '<App/>',
//components: { App }
//})

Date.prototype.format = function(fmt) { 
     var o = { 
        "M+" : this.getMonth()+1,                 //月份 
        "d+" : this.getDate(),                    //日 
        "h+" : this.getHours(),                   //小时 
        "m+" : this.getMinutes(),                 //分 
        "s+" : this.getSeconds(),                 //秒 
        "q+" : Math.floor((this.getMonth()+3)/3), //季度 
        "S"  : this.getMilliseconds()             //毫秒 
    }; 
    if(/(y+)/.test(fmt)) {
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
    }
     for(var k in o) {
        if(new RegExp("("+ k +")").test(fmt)){
             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
         }
     }
    return fmt; 
} 



import Vue from 'vue'
import YDUI from 'vue-ydui'
import MuseUI from 'muse-ui'
import 'muse-ui/dist/muse-ui.css'
import Mint from 'mint-ui'
import 'mint-ui/lib/style.css'
Vue.use(Mint)

Vue.use(MuseUI)
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper)
//import ElementUI from 'element-ui'
//import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import store from './store'
import publicData from './assets/js/public.js'
Vue.use(publicData)
import {runJquery} from '@/assets/js/runJQ.js'
Vue.use(runJquery)//等同于runJquery()

import TopNav from '@/components/nav/topNav.vue'
import classInfo from '@/components/classInfo/classInfo.vue'
import {DateTime} from 'vue-ydui/dist/lib.rem/datetime' 
import {Popup} from 'vue-ydui/dist/lib.rem/popup'
Vue.component(DateTime.name, DateTime)
Vue.component('TopNav',TopNav)
Vue.component('classInfo',classInfo)
Vue.component(Popup.name, Popup)
//import locale from 'element-ui/lib/locale/lang/en'

//Vue.prototype.axios = axios;
//Vue.config.productionTip = false

  // axios 配置
axios.defaults.timeout = 50000;
//根目录
axios.defaults.baseURL = '';
    // http request 拦截器
axios.interceptors.request.use(
config => {
    if (localStorage.token!=null) {
      config.params  = config.params||{}
      config.params.token = localStorage.token;
    }
    return config;
},
err => {
    return Promise.reject(err);
});

// http response 拦截器
// 监测是否登陆了
axios.interceptors.response.use(
	  response => {
    switch (response.data.code) {
      case 401:
        // 401 清除token信息并跳转到登录页面
//         router.replace({
//           path: this.$store.state.loginUrl,
//           query: {redirect: router.currentRoute.fullPath}
//        
//         })
		//window.location.href=myVue.$store.state.loginUrl
    }
    return response;
},
error => {
    throw error
});
Vue.prototype.axios = axios;
//Vue.use(ElementUI, { locale })

Vue.config.productionTip = false


/* eslint-disable no-new */
var myVue= new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
//axios
});




// 判断是否需要登录权限 以及是否登录
	router.beforeEach(
		(to, from, next) => {
    if (to.matched.some(r => r.meta.requireAuth)) {
        if (localStorage.token!=null) {
            next();
          }
        else {
            next({
                path: '/login',
                query: {redirect: to.fullPath}
            })
        }
    }
    else {
        next();
    }
})
(function(){
	 if (localStorage.token!=null) {
	 	if(myVue.$store.state.token==null){
	 		myVue.$store.commit('init')
	 	}}
}());

